package cn.assumejson.springframework.aop.aspectj.annotation;

import cn.assumejson.springframework.aop.Pointcut;
import cn.assumejson.springframework.aop.aspectj.AspectJExpressionPointcut;
import cn.assumejson.springframework.aop.aspectj.autoproxy.InstantiationModelAwarePointcutAdvisor;
import org.aopalliance.aop.Advice;

import java.io.Serializable;
import java.lang.reflect.Method;

/**
 * @author gang.Li
 * @version 1.0
 * @since 1.0 2021/12/9 18:34
 */
public class InstantiationModelAwarePointcutAdvisorImpl implements InstantiationModelAwarePointcutAdvisor, Serializable {

    private static final Advice EMPTY_ADVICE = new Advice() {
    };


    private final AspectJExpressionPointcut declaredPointcut;

    private final Class<?> declaringClass;

    private final String methodName;

    private final Class<?>[] parameterTypes;

    private transient Method aspectJAdviceMethod;


    private final String aspectName;

    private final Pointcut pointcut;

    private Advice instantiatedAdvice;

    private Boolean isBeforeAdvice;

    private Boolean isAfterAdvice;

    public InstantiationModelAwarePointcutAdvisorImpl(AspectJExpressionPointcut declaredPointcut, Method method, ReflectiveAspectJAdvisorFactory reflectiveAspectJAdvisorFactory, String aspectName) {
        this.declaredPointcut = declaredPointcut;
        this.declaringClass = method.getDeclaringClass();
        this.methodName = method.getName();
        this.parameterTypes = method.getParameterTypes();
        this.aspectJAdviceMethod = method;
        this.aspectName = aspectName;


        this.pointcut = this.declaredPointcut;
    }



    @Override
    public Advice getAdvice() {
        return null;
    }

    @Override
    public Pointcut getPointcut() {
        return this.pointcut;
    }

    public AspectJExpressionPointcut getDeclaredPointcut() {
        return declaredPointcut;
    }

    public Class<?> getDeclaringClass() {
        return declaringClass;
    }

    public String getMethodName() {
        return methodName;
    }

    public Class<?>[] getParameterTypes() {
        return parameterTypes;
    }

    public Method getAspectJAdviceMethod() {
        return aspectJAdviceMethod;
    }

    public void setAspectJAdviceMethod(Method aspectJAdviceMethod) {
        this.aspectJAdviceMethod = aspectJAdviceMethod;
    }

    @Override
    public String getAspectName() {
        return aspectName;
    }

    public Advice getInstantiatedAdvice() {
        return instantiatedAdvice;
    }

    public void setInstantiatedAdvice(Advice instantiatedAdvice) {
        this.instantiatedAdvice = instantiatedAdvice;
    }

    public Boolean getBeforeAdvice() {
        return isBeforeAdvice;
    }

    public void setBeforeAdvice(Boolean beforeAdvice) {
        isBeforeAdvice = beforeAdvice;
    }

    public Boolean getAfterAdvice() {
        return isAfterAdvice;
    }

    public void setAfterAdvice(Boolean afterAdvice) {
        isAfterAdvice = afterAdvice;
    }
}
